package route

import (
	"fmt"
	"github.com/gin-gonic/gin"
	gs "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	"hello/api"
	_ "hello/docs"
	sql "hello/mysql"
	"hello/tools"
)

func InitRouter() {
	router := gin.Default()
	router.Use(tools.Cors())
	router.Use(tools.TlsHandler())
	err := sql.InitDB()
	if err != nil {
		fmt.Printf("init db failed,err:%v\n", err)
	}
	router.GET("/parse",api.ParseToken)
	router.POST("/auth", api.AuthHandler) // 生成token(id,name,number)
	router.GET("/img", api.GetImgArr)     // 获得所有的图片素材
	router.GET("/swagger/*any", gs.WrapHandler(swaggerFiles.Handler))
	team := router.Group("/team")
	{
		team.GET("", api.GetAllTeamers)    // 获得工作室目前所有的成员
		team.GET("/div", api.GetTeamClass) // 获得不同类别的所有工作室成员
	}
	user := router.Group("/user")
	{
		user.GET("/name",api.GetUserByName)
		user.GET("/sex/class",api.GetGenderForClasses)
		user.GET("/sex",api.GetUserSex)
		user.GET("/all", api.GetAllUser) // 获得所有的用户
		user.GET("", api.GetUser)        // 查询
		user.POST("", api.LoginDB)       // 增加
		user.PUT("", api.ModifyUser)     // 修改 (权限认证)
		user.DELETE("", api.DeleteUser)  // 删除 (权限认证)
	}
	comment := router.Group("/comment")
	{
		comment.GET("/name",api.GetCommentByName)
		comment.GET("/all", api.GetAllComments) // 获取所有的评论
		comment.GET("", api.GetSingleComment)   // 获得一条评论
		comment.POST("", api.InsertComment)     // 增加一条评论
		comment.PUT("", api.UpdateComment)      // 修改评论内容 (权限认证)
		comment.DELETE("", api.DeleteComment)   // 删除一条评论 (权限认证)
	}
	process := router.Group("/process")
	{
		process.GET("/all",api.GetAllProcesses)   	// 获取所有的流程信息
		process.GET("/:id",api.GetSingleProcess)	// 根据编号获取单个流程
		process.PUT("",api.UpdateProcess)			// 根据表单数据来更新某个流程
	}

	show := router.Group("/show")
	{
		show.GET("/class",api.GetShowDataClassSum)
		show.GET("/all",api.GetAllShowData)
		show.GET("/:type",api.GetClassShowData)
	}
	mail := router.Group("/mail")
	{
		mail.POST("/:target/:title/:content",api.SendEmail)
	}

	award := router.Group("/award")
	{
		award.GET("/all",api.GetAllAward)
	}

	yuqAdmin := router.Group("/yuq")
	{
		yuqAdmin.POST("/:qq",api.AddYuqAdmin)
		yuqAdmin.GET("/all",api.GetAllYuqAdmin)
		yuqAdmin.GET("/music",api.CheckMusicName)
	}

	//router.Run(":8088")
	router.RunTLS(":8081","ssl.pem","ssl.key")
}

